/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 *
 *       This program is free software; you can redistribute it and/or
 *       modify it under the terms of the GNU Lesser General Public License
 *       as published by the Free Software Foundation; either version 2.1
 *       of the License, or (at your option) any later version.
 *
 *       This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *       GNU Lesser General Public License for more details.
 *
 *       You should have received a copy of the GNU Lesser General Public License
 *       along with this program; if not, write to the Free Software
 *       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 * 
 */
package ca.usherbrooke.agent.controller.shared;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;

/**
 * @author Cody Stoutenburg
 * 
 */
public class IMessage implements Externalizable {
	private static final long serialVersionUID = 1L;

	private Long guidSender;
	private String objet;
	private Serializable object;
	private String message;

	public IMessage() {
		this(0L, "", "");
	}

	public IMessage(Long guidSender, String objet, String message) {
		this(guidSender, objet, null, message);
	}

	/**
	 * @param guidSender
	 * @param objet
	 * @param object
	 * @param message
	 */
	public IMessage(Long guidSender, String objet, Serializable object,
			String message) {
		super();
		this.guidSender = guidSender;
		this.objet = objet;
		this.object = object;
		this.message = message;
	}

	/**
	 * get the guid of the sender
	 * 
	 * @return the guid of the sender
	 */
	public Long getGuidSender() {
		return guidSender;
	}

	/**
	 * get the object of the message
	 * 
	 * @return the object of the message
	 */
	public String getObjet() {
		return objet;
	}

	/**
	 * get the serializable object of the message
	 * 
	 * @return the serializable object of the message
	 */
	public Serializable getObject() {
		return object;
	}

	/**
	 * get the string part of the message
	 * 
	 * @return the string part of the message
	 */
	public String getMessage() {
		return message;
	}

	@Override
	public void writeExternal(ObjectOutput out) throws IOException {
		out.writeLong(this.guidSender);
		out.writeObject(this.objet);
		out.writeObject(this.object);
		out.writeObject(this.message);
	}

	@Override
	public void readExternal(ObjectInput in) throws IOException,
			ClassNotFoundException {
		this.guidSender = in.readLong();
		this.objet = (String) in.readObject();
		this.object = (Serializable) in.readObject();
		this.message = (String) in.readObject();
	}
}
